package com.witframework.web.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class SessionExpireTag extends BodyTagSupport
{
  private String url = "index.jsp";

  public void setUrl(String paramString)
  {
    this.url = paramString;
  }

  public String getUrl()
  {
    return this.url;
  }

  public int doEndTag()
    throws JspException
  {
    StringBuffer localStringBuffer = new StringBuffer("");
    localStringBuffer.append("\n<script language=\"JavaScript\" type=\"text/javascript\">\n");
    localStringBuffer.append("function cjExpireSession() { window.location='");
    localStringBuffer.append(getUrl());
    localStringBuffer.append("'; }\n");
    HttpServletRequest localHttpServletRequest = (HttpServletRequest)this.pageContext.getRequest();
    HttpSession localHttpSession = localHttpServletRequest.getSession();
    if (localHttpSession == null)
    {
      localStringBuffer.append("cjexpireSession();\n");
    }
    else
    {
      localStringBuffer.append("setTimeout('cjExpireSession()',");
      localStringBuffer.append((localHttpSession.getMaxInactiveInterval() * 1000) + ");\n");
    }
    localStringBuffer.append("</script>\n");
    try
    {
      this.pageContext.getOut().write(localStringBuffer.toString());
    }
    catch (Exception localException)
    {
      throw new JspException("Could not write data " + localException.toString());
    }
    dropData();
    return 6;
  }

  public void release()
  {
    super.release();
    dropData();
  }

  private void dropData()
  {
    this.url = "index.jsp";
  }
}